<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/4/16
  Time: 14:36
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>添加汉字用户</title>
    <link rel="shortcut icon" href="favicon.ico">
    <link href="/static/css/bootstrap.min.css" rel="stylesheet">
    <link href="/static/css/font-awesome.min93e3.css" rel="stylesheet">
    <link href="/static/css/plugins/datapicker/datepicker3.css" rel="stylesheet">
    <link href="/static/css/style.min.css?v=4.1.0" rel="stylesheet">

    <script src="/static/js/jquery.min.js"></script>
    <script src="/static/layer/layer.js"></script>
    <script src="/static/js/bootstrap.min.js"></script>
    <script src="/static/js/content.min.js?v=1.0.0"></script>
    <script src="/static/js/plugins/datapicker/bootstrap-datepicker.js"></script>


</head>

<body>

<div style="padding: 15px;">
    <table class="table">
        <tr>
            <td width="80">用户名</td>
            <td><input type="text" class="form-control" name="username" placeholder="请输入用户名"></td>
        </tr>
        <tr>
            <td>手机号</td>
            <td><input type="text" class="form-control" name="tel" placeholder="请输入手机号"></td>
        </tr>
        <tr>
            <td>身份证</td>
            <td><input type="text" class="form-control" name="card" placeholder="请输入身份证"></td>
        </tr>
        <tr>
            <td>学习科目</td>
            <td><input type="text" class="form-control" name="studysub" placeholder="请输入学习科目"></td>
        </tr>
        <tr>
            <td>用户地址</td>
            <td><input type="text" class="form-control" name="place" placeholder="请输入用户地址"></td>
        </tr>
        <tr>
            <td>缴纳学费</td>
            <td><input type="text" class="form-control" name="money" placeholder="请输入缴纳学费"></td>
        </tr>
        <tr>
            <td>驾校名称</td>
            <td><input type="text" class="form-control" name="drivename" placeholder="请输入驾校名称"></td>
        </tr>
        <tr>
            <td>用户分组</td>
            <td>
                <input id="usergroup" type="text" class="form-control" name="group" placeholder="请选择分组" readonly>
                <input id="sareaId" type="hidden" class="form-control">
                <input id="careaId" type="hidden" class="form-control">
                <input id="jareaId" type="hidden" class="form-control">
            </td>
        </tr>
        <tr>
            <td>使用语种</td>
            <td>
                <select id="language" class="form-control">
                    <option value="1">汉字</option>
                    <option value="2">藏文</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>使用期限</td>
            <td>
                <div id="data_1">
                    <div class="input-group date">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input id="datachose" type="text" class="form-control" name="timelimit" readonly
                               placeholder="请选择会员到期时间">
                    </div>
                </div>
            </td>
        </tr>

    </table>
    <button class="btn btn-primary btn-lg btn-block AjaxForm">提交保存</button>
</div>


<script>
    $(function () {
        $('#datachose').datepicker({
            format: 'yyyy-mm-dd', minView: 2, autoclose: true, language: 'zh-CN'
        });

        $("#usergroup").click(
            function () {
                var ind = layer.open({
                    type: 2,
                    title: '用户分组',
                    area: ['300px', '450px'],
                    fixed: false, //不固定
                    maxmin: false,
                    content: '/page/user/group_user.jsp',
                    btn: ['<i class="fa fa-check"></i> 确定', '<i class="fa fa-close"></i> 关闭'],
                    yes: function (index, layero) {
                        //按钮【按钮一】的回调
                        var $form = layer.getChildFrame('form', index);
                        var name = $form.find(".form-group").attr("name");
                        var iframeWin = window[layero.find('iframe')[0]['name']];//得到iframe页的窗口对象，执行iframe页的方法：
//                        console.info(iframeWin.getIds());
                        var arr = iframeWin.getIds();
                        for (var i = 0; i < arr.length; i++) {
                            if (arr[i].type == 0) {
                                $("#jareaId").attr("name", arr[i].id);
                            }
                            if (arr[i].type == 1) {
                                $("#careaId").attr("name", arr[i].id);
                            }
                            if (arr[i].type == 2) {
                                $("#sareaId").attr("name", arr[i].id);
                            }
                        }
                        $("#usergroup").attr("value", name);
                        layer.close(ind);
                    }
                    , btn2: function (index, layero) {
                        //按钮【按钮二】的回调
                        layer.close(ind);
                    }
                });
            });

        $(".AjaxForm").click(function () {
            var username = $('input[name=username]').val(),
                tel = $('input[name=tel]').val(),
                card = $('input[name=card]').val(),
                studysub = $('input[name=studysub]').val(),
                place = $('input[name=place]').val(),
                money = $('input[name=money]').val(),
                drivename = $('input[name=drivename]').val(),
                provinceid = $('#sareaId').attr("name"),
                cityid = $('#careaId').attr("name"),
                jiaid = $('#jareaId').attr("name"),
//                group = $("#usergroup").attr("name"),
//                group = $("input[name=group]").val(),
                race = $("#language option:selected").val(),
                timelimit = $('input[name=timelimit]').val(),
                data;
            if (!username) {
                layer.msg('请输入用户名', {icon: 2, time: 1000});
                $('input[name=username]').focus();
                return false;
            }
            if (!tel) {
                layer.msg('请输入手机号', {icon: 2, time: 1000});
                $('input[name=tel]').focus();
                return false;
            }
            if (!card) {
                layer.msg('请输入身份证', {icon: 2, time: 1000});
                $('input[name=card]').focus();
                return false;
            }
            if (!studysub) {
                layer.msg('请输入学习科目', {icon: 2, time: 1000});
                $('input[name=studysub]').focus();
                return false;
            }
            if (!place) {
                layer.msg('请输入用户地址', {icon: 2, time: 1000});
                $('input[name=place]').focus();
                return false;
            }
            if (!money) {
                layer.msg('请输入缴纳学费', {icon: 2, time: 1000});
                $('input[name=money]').focus();
                return false;
            }
            if (!drivename) {
                layer.msg('请输入驾校名称', {icon: 2, time: 1000});
                $('input[name=drivename]').focus();
                return false;
            }
            /*if (!group){
                group = 1000000;
                return true;
            }*/
            if (!race) {
                layer.msg('请选择语言', {icon: 2, time: 1000});
                $('select #language').focus();
                return false;
            }
            if (!timelimit) {
                layer.msg('请选择会员到期时间', {icon: 2, time: 1000});
                $('input[name=timelimit]').focus();
                return false;
            }


            data = {
                username: username,
                tel: tel,
                card: card,
                studysub: studysub,
                place: place,
                money: money,
                drivename: drivename,
                race: race,
                jareaId: jiaid,
                careaId: cityid,
                sareaId: provinceid,
                timelimit: timelimit
            };
            console.info(data);
            $.ajax({
                type: 'POST',
                url: "/user",
                data: data,
                dataType: 'json',
                success: function (json) {
                    if (json.status == "success") {
                        layer.msg('添加成功', {icon: 1, time: 1000});
                        setTimeout(function () {
                            parent.location.reload();
                        }, 1000);
                    }
                },
                error: function () {
                    layer.msg('服务器繁忙，请刷新页面后重试', {icon: 5, time: 1000});
                }
            });
        });

    })

</script>
</body>

</html>
